package cn.bigfire.compiler.dragon.appendixA.handwrite.symbols;

import cn.bigfire.compiler.dragon.appendixA.handwrite.inter.Id;
import cn.bigfire.compiler.dragon.appendixA.handwrite.lexer.Token;

import java.util.Hashtable;

public class Env {
    public Hashtable<Token, Id> table = new Hashtable<Token, Id>();

    protected Env prev;

    public Env(Env env) {
        prev = env;
    }

    public void put(Token token, Id id) {
        table.put(token, id);
    }


    public Id get(Token w) {
        for (Env env = this; env != null; env = env.prev) {
            Id found = env.table.get(w);
            if (found != null) {
                return found;
            }
        }
        return null;
    }


}
